/* 
 *  Incub - incubate your baby robot
 *  Copyright (C) 2008 Stanislaw Szymczyk
 *  e-mail: sszymczy@gmail.com   www: http://cogville.cog-lab.com
 *
 *  This file is part of Incub.
 *
 *  Incub is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Incub is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Incub.  If not, see <http://www.gnu.org/licenses/>.
 * 
 */
 
#ifndef CORBA_H_
#define CORBA_H_

#include <utility>
#include <vector>
#include <string>
#include <boost/thread/mutex.hpp>

#include "CorbaImplementations.h"
#include "World.h"
#include "Shape.h"
#include "Joint.h"
#include "Gate.h"
#include "ClientCallback.h"
#include "incub.hh"

class World;
class Gate;

class Corba {
	private:
	static Gate* gate;
	static std::vector<std::string> callbacks;
	static CORBA::ORB_ptr orb;
	static PortableServer::POA_var poa;
	static VShapeOut* activateShape(Shape* shape);
	static std::pair<VJointOut*, VJointIn*> activateJoint(Joint* joint);
	static std::pair<VEntityOut*, VEntityIn*> activateEntity(Entity* entity);
	static std::pair<VWorldOut*, VWorldIn*> activateWorld(World* world);
	static void copyShape(VShapeOut*, Shape* shape);
	static void copyJoint(VJointOut*, Joint* joint);
	static void copyEntity(VEntityOut*, Entity* entity);
	static void copyWorld(VWorldOut*, World* world);
	static void bindObjectToName(CORBA::ORB_ptr orb, CORBA::Object_ptr objref);
	public:
	static void init(int argc, char **argv, World*);
	static void cleanup();
	static void step();
	static void registerCallback(IClientCallback_ptr call);
	static void unregisterCallback(IClientCallback_ptr call);
	static boost::mutex mutex;
	public:
	class CorbaException : public std::exception {
		protected: std::string msg;
		public: 
		CorbaException(char *m) { msg = std::string(m); }
		virtual const char* what() const throw() { return msg.c_str(); }
		~CorbaException () throw () {};
	};	
};

#endif /*CORBA_H_*/
